

package org.example.flinksql.source;

import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.net.URL;

/**
 * Skeleton for a Flink Streaming Job.
 *
 * <p>For a tutorial how to write a Flink streaming application, check the
 * tutorials and examples on the <a href="https://flink.apache.org/docs/stable/">Flink Website</a>.
 *
 * <p>To package your application into a JAR file for execution, run
 * 'mvn clean package' on the command line.
 *
 * <p>If you change the name of the main class (with the public static void main(String[] args))
 * method, change the respective entry in the POM.xml file (simply search for 'mainClass').
 */
public class File {

	public static void main(String[] args) throws Exception {
		// set up the streaming execution environment
		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

		/*
		 * Here, you can start creating your execution plan for Flink.
		 *
		 * Start with getting some data from the environment, like
		 * 	env.readTextFile(textPath);
		 *
		 * then, transform the resulting DataStream<String> using operations
		 * like
		 * 	.filter()
		 * 	.flatMap()
		 * 	.join()
		 * 	.coGroup()
		 *
		 * and many more.
		 * Have a look at the programming guide for the Java API:
		 *
		 * https://flink.apache.org/docs/latest/apis/streaming/index.html
		 *
		 */

		String filePath = "D:\\playground\\Flink-demo\\src\\main\\resources\\keyword.txt";
		DataStreamSource<String> source = env.readTextFile(filePath);
		source.print();

		URL resource = Thread.currentThread().getContextClassLoader().getResource("keyword.txt");
		String filePath2 = resource.toString();
		DataStreamSource<String> source2 = env.readTextFile(filePath2, "utf8");
		source2.print();
		String filePath3 = resource.getPath();
		DataStreamSource<String> source3 = env.readTextFile(filePath3, "utf8");
		source3.print();

		String filePath4 = resource.getPath();
		DataStreamSource<String> source4 = env.readFile(new TextInputFormat(new Path(filePath4)), filePath4);
		source4.print();


		// execute program
		env.execute("Flink Streaming Java API Skeleton");
	}
}
